Graph Coloring: Chromatic Number ($\chi(G)$)
Implement the Greedy Algorithm to find an upper bound for the Chromatic Number.
ā The Coloring Challenge
The **Chromatic Number ($\chi(G)$)** is the smallest number of colors needed to color the vertices of a graph $G$ such that no two adjacent vertices share the same color. Finding the exact chromatic number is generally **NP-hard**.
We will use the **Greedy Coloring Algorithm**, which provides a fast and practical **upper bound** on $\chi(G)$.
Input Section (Adjacency Matrix)
Graph Visualization (Initial):
š” The Greedy Coloring Strategy
The Core Rule: Minimum Excluded (MEX) Color
The greedy approach colors vertices one by one based on a fixed order (in this demo, the input order $0, 1, 2, \dots$ ).
- **Vertex Order:** Process vertices in a fixed sequence (e.g., $V_0, V_1, V_2, \dots$).
- **Check Neighbors:** For the current vertex $u$, check the colors already assigned to its neighbors.
- **Assign MEX:** Assign the **smallest positive integer color (1, 2, 3, ...)** that is *not* used by any of $u$'s neighbors.
- **Repeat:** Continue until all vertices are colored. The number of colors used is the result.
Color Palette Used:
š¬ Step-by-Step Coloring Demo
Process Log:
Coloring Progress:
Final Chromatic Number (Greedy Result):
š Analysis & Limitations
Time Complexity
O(V² + V * $\Delta$)
Where $V$ is vertices and $\Delta$ is max degree. In the worst case for dense graphs, this is **O(V³)** or $O(V \cdot (V+V)) = O(V^2)$ if neighbor check is $O(V)$ and finding the color is $O(V)$. Very efficient!
Space Complexity
O(V² + V)
Required to store the Adjacency Matrix ($O(V^2)$) and the color array ($O(V)$).
Limitation of Greedy Coloring
The greedy algorithm is a **heuristic**, meaning it doesn't always find the true minimum chromatic number ($\chi(G)$). The result depends heavily on the **order** in which the vertices are processed. Changing the vertex order (e.g., using saturation degree) can often yield a better, or minimum, result, but the simple order used here is the most basic implementation.